﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net;

namespace Ajax_GiuaKy
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        HttpClient client;
        protected void Page_Load(object sender, EventArgs e)
        {
            client = new HttpClient();
            client.BaseAddress = new Uri("http://localhost:2425/");
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            var acc = new AccountDTO();
            acc.TaiKhoan = TextBox_User.Text;
            acc.MatKhau = TextBox_Pass.Text;
            acc.TinhTrang = false;

            HttpResponseMessage response = client.PostAsJsonAsync("api/chat?signup=", acc).Result;
            int kq = response.Content.ReadAsAsync<int>().Result;
            if (kq == 1)
            {
                Byte[] imgbyte = FileUpload_Img.FileBytes;
                client.PostAsJsonAsync<Byte[]>("api/chat?hinhanh=" + TextBox_User.Text, imgbyte);

                Response.Redirect("~/Default.aspx");
            }
        }

    }
}